home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Freeware
/
Read It Later 0.9924
/
read_it_later-0.9924-fx.xpi
/
chrome
/
isreaditlater.jar
/
content
/
ISRIL.js
< prev
next >
Wrap
Text File
|
2008-11-02
|
37KB
|
1,115 lines
function ISRILmaster()
{
// -- Version Information -- //
this.v = '0.9920';
this.cl = 'http://www.ideashower.com/blog/read-it-later-099-released/'; //changelog address
this.appId = 'isreaditlater';
// -- Init Settings -- //
this.inited = false;
// -- Defining Starting Variables -- //
this.listDrops = new Array();
this.adding = false;
this.ClickModeNodesN = 0;
this.channels = new Object();
// -- General Settings -- //
this.autoMarkWait = 5; //seconds
}
ISRILmaster.prototype = {
// --- Folder --- //
loadFolder : function() {
if (ISRILprefs.prefIsSet('folderId') && ISRIL.folderExists(ISRILprefs.pref('folderGUID')) ) {
ISRILglobals.folderId = ISRILprefs.pref('folderId');
} else {
//do a quick look to find a folder called 'Read It Later'
var folders = ISRIL.GetAllFolders();
for(i in folders) {
if (folders[i] && folders[i].node && folders[i].node.title == 'Read It Later') {
ISRILglobals.folderId = folders[i].node.itemId;
var newFolder = true;
break;
}
}
if (!newFolder) {
//Create New Folder
ISRILglobals.folderId = ISRIL.sBookmarks.createFolder(
ISRIL.sBookmarks.bookmarksMenuFolder, // The id of the folder the new folder will be placed in.
"Read It Later", // The title of the new folder.
ISRIL.sBookmarks.DEFAULT_INDEX); // The position of the new folder in it's parent folder.
}
ISRILprefs.setPref('folderId', ISRILglobals.folderId);
ISRILprefs.setPref('folderGUID', ISRIL.sBookmarks.getItemGUID( ISRILglobals.folderId ));
ISRILsync.getUpdatesStart(true);
}
},
folderExists : function(id) {
return ( (ISRIL.sBookmarks.getItemIdForGUID( id ) == -1) ? (false):(true) );
},
saveNewFolder : function(id) {
ISRILprefs.setPref('folderId', id );
ISRILprefs.setPref('folderGUID', ISRIL.sBookmarks.getItemGUID( id ));
ISRIL.loadFolder();
//ISRILsync.sendFolder(); //Let them manually sync as not to duplicate old items
ISRILglobals.CacheStale = true;
},
// --- Get Vars --- //
url : function() {
return ( (!getBrowser().currentURI.spec) ? (false):(getBrowser().currentURI.spec) );
},
title : function() {
return getBrowser().contentDocument.title;
},
uri : function(uri) {
return ISRIL.ios.newURI(uri, null, null);
},
// --- On Page Load --- //
checkLoad : function(e) {
if (e.originalTarget instanceof HTMLDocument) {
var doc = e.originalTarget;
if (e.originalTarget.defaultView.frameElement) {
// Frame within a tab was loaded. doc should be the root document of
// the frameset. If you don't want do anything when frames/iframes
// are loaded in this web page, uncomment the following line:
return false;
}
ISRIL.checkPage();
}
},
checkPage : function() {
if (ISRIL.url() != 'about:blank') {
var Search = ISRIL.findItem();
if (Search[0] && Search[1] == 1 && !navigator.onLine) { ISRILoffline.Serve( Search[0] ); }
//check url against...
ISRILgr.check();
return ISRILxul.SetBtn( ((Search[0])?(2):(1)) );
}
return ISRILxul.SetBtn();
},
findItem : function() {
var id = false;
var type = false;
if (!navigator.onLine && decodeURI( ISRIL.url() ).match(new RegExp(ISRILoffline.prefix + '([0-9]+)'))) {
try {
var i = RegExp.$1;
if ( ISRIL.sBookmarks.getBookmarkURI(i).spec ) {
id = ( (i != -1) ? (i):(null) );
type = 2;
}
} catch(e) {
//item no longer exists (probably was marked as read in offline mode
}
} else {
id = ISRIL.InList( ISRIL.url() );
type = 1;
}
return new Array(id,type);
},
// --- List Management --- //
Save : function(url, title, nosync) {
//If Read It Later Folder Doesn't Exist, prompt for a new folder.
if (!ISRILprefs.prefIsSet('folderId') || !ISRIL.folderExists(ISRILprefs.pref('folderGUID')) ) {
var list = new Array( ISRIL.l('CreateOne')+'...' );
var selected = {};
folders = ISRIL.GetAllFolders();
for(i in folders) {
list.push( folders[i].node.title );
}
var ok = ISRIL.sPrompts.select(window, ISRIL.l('ReadItLater'), ISRIL.l('NoFolder'),
(list.length < 7)?list.length:7, list, selected);
if (ok) {
if (selected.value == 0) {
ISRIL.loadFolder();
} else {
ISRIL.saveNewFolder( folders[selected.value-1].node.itemId );
}
} else {
return false;
}
}
// -- Default Variables
//If url was not sent, then assume it's the page we're on and that it was saved via checkmark
if (!url) {
url = ISRIL.url();
var fromCheckmark = true;
}
if (!title) { title = ISRIL.title(); }
// -- Attempt to add
if (!ISRIL.InList(url)) {
//Check that it's a website and not local or ftp, etc
parsed = ISRIL.parseUri(url);
if (parsed.protocol == 'http' || parsed.protocol == 'https') {
ISRILglobals.adding = true; //start
//Add Bookmark
bookmarkId = ISRIL.sBookmarks.insertBookmark(
ISRILglobals.folderId, // The id of the folder the bookmark will be placed in.
ISRIL.uri(url), // The URI of the bookmark - an nsIURI object.
ISRIL.sBookmarks.DEFAULT_INDEX, // The position of the bookmark in it's parent folder.
title); // The title of the bookmark.
//Add Auto-tags
if (ISRILprefs.pref('auto-tags').length > 0) {
ISRIL.sTags.tagURI( ISRIL.uri(url), ISRILprefs.pref('auto-tags').split(','), 1 ); //add all tags
}
//Prepare to Sync
if (!nosync) {ISRILsync.QueueNew( bookmarkId ); }
ISRILglobals.adding = false; //end
ISRIL.ListSizeInc(1);
ISRIL.checkPage();
if (fromCheckmark) {
if (ISRILprefs.prefB('autoOffline')) {
ISRILoffline.saveDoc( getBrowser().contentDocument , bookmarkId); //skip download queue since doc is already open
}
if ( ISRILprefs.prefB('auto-close-tab')) {
gBrowser.removeCurrentTab();
}
}
return bookmarkId;
} else {
ISRILxul.sPrompt.alert(window, ISRIL.l('ReadItLater'), ISRIL.l('OnlyWebsites') );
}
}
return false;
},
SaveLink : function(url, title) {
url = ( (!url && gContextMenu) ? (gContextMenu.linkURL):(url) );
title = ( (!title && gContextMenu) ? (gContextMenu.linkText()):(title) );
bookmarkId = ISRIL.Save(url, title, true);
if (bookmarkId) {
//if (ISRILprefs.prefB('autoOffline')) {
// ISRILoffline.addToQueue( bookmarkId, true );
//} else {
// ISRIL.ResolveLink(url, ISRIL.SaveLinkBack, bookmarkId);
//}
ISRIL.ResolveLink(url, ISRIL.SaveLinkBack, bookmarkId, true);
}
ISRILsync.QueueNew( bookmarkId , url, ISRILsync.syncTimeWaitResolve );
//Save original URL in resolver
var sql = "REPLACE INTO ril_link_resolver (id, original_url) VALUES (?1, ?2)"
var statement = ISRIL.DB.createStatement(sql);
statement.bindInt32Parameter(0, bookmarkId);
statement.bindUTF8StringParameter(1, url);
statement.execute();
statement.reset();
},
SaveLinkBack : function(url, id, offline) {
if (url != ISRIL.sBookmarks.getBookmarkURI( id ).spec) { //changed
if (!ISRIL.InList(url)) { //resolved url doesn't already exist in saved
ISRIL.sBookmarks.changeBookmarkURI( id , ISRIL.uri(url) );
} else {
//remove unresolved link and don't save new one, also don't sync this old page as read
if ( ISRILglobals.ListCache[ id ] ) { ISRILglobals.ListCache[ id ] = false ; }
ISRIL.sBookmarks.removeItem( id, true );
return false;
}
ISRILsync.QueueNew( id , url, ISRILsync.syncTimeIncBatch );
}
if (offline) {
ISRILoffline.addToQueue( id, true );
}
},
ResolveLink : function(url, callback, id, offline) {
ISRIL.channels[ id ] = ISRIL.ios.newChannelFromURI( ISRIL.uri(url) );
// get an listener
var listener = new ISRIL.listener_linkResolve(callback, url, id, offline);
ISRIL.channels[ id ].notificationCallbacks = listener;
ISRIL.channels[ id ].asyncOpen(listener, null);
},
SaveTabs : function() {
var num = gBrowser.browsers.length;
for (var i = 0; i < num; i++) {
var b = gBrowser.getBrowserAtIndex(i);
ISRIL.Save( b.currentURI.spec , b.contentTitle );
}
},
MarkAsRead : function(id, nogo, service, noSync) {
if (!id) {
var Search = ISRIL.findItem();
id = Search[0];
}
service = ( (!service) ? ('') : (service) ); //don't need this anymore
if (id) {
var index = ISRIL.sBookmarks.getItemIndex( id ); //only need this if !nogo
ISRILoffline.deleteOffline( id ); //maybe queue this up and do batches?
if (!noSync) {
ISRILsync.QueueUpdate(id, 'read');
}
ISRILglobals.noSyncId = id;
ISRIL.sBookmarks.removeItem(id);
ISRIL.ListSizeInc(-1);
if (!nogo) {
if ( ISRILprefs.pref('mark') == 'close' ) {
gBrowser.removeCurrentTab();
} else {
if (ISRILglobals.ListSize > 0) {
switch(ISRILprefs.pref('mark')) {
case('next'): ISRIL.Next(index-1); break;
case('rand'): ISRIL.RandRead(); break;
}
}
}
}
ISRIL.checkPage(); //this doesn't have to happen to happen on batches, otherwise it's firing a lot!
ISRIL.resolverRemove(id);
}
},
autoMark : function() {
if (ISRILprefs.prefB('autoMark') && !ISRILxul.mark1.hidden) {
ISRIL.MarkAsRead();
}
},
resolverRemove : function(id) {
try {
var sql = "DELETE FROM ril_link_resolver WHERE id = ?1"
var statement = ISRIL.DB.createStatement(sql);
statement.bindInt32Parameter(0, id);
statement.execute();
statement.reset();
} catch(err) {}
},
// --- Browser --- //
Open : function(url) {
openUILinkIn(url, ISRILxul.ButtonTarget?ISRILxul.ButtonTarget.targ:ISRILprefs.pref('open'));
},
GoTo : function(url, offline, targ, ref) {
if (offline) { ISRILoffline.curOff = offline; }
targ = ((targ)?(targ):('current'));
openUILinkIn(url, targ, null, null, ref?ISRIL.uri(ref):null);
},
OpenById : function(id) {
if (id) {
ISRIL.Open( ISRIL.sBookmarks.getBookmarkURI(id).spec );
} else {
ISRILxul.OpenReadingList(true);
}
},
Read : function() {
if (ISRILglobals.CacheStale) {
ISRIL.GetList( ISRILxul.Sort.selectedItem.getAttribute('value'), ISRILxul.Filter.value );
}
if (!ISRILglobals.ListSize || ISRILglobals.ListSize == 0 || ISRILprefs.pref('read') == 'list' || ISRIL_init.startupError) {
ISRILxul.ToggleReadingList();
} else {
switch( ISRILprefs.pref('read') ) {
case('next'):
curUrl = ISRIL.url();
var index = -1;
if (curUrl) {
id = ( (!navigator.onLine && ISRILoffline.curOff) ? (ISRILoffline.curOff):(ISRIL.InList(curUrl)) );
if (id) {
index = ISRILglobals.ListIndexI[ id ];
}
}
ISRIL.Next( index );
break;
case('rand'): ISRIL.RandRead(); break;
}
}
},
Next : function(index) {
index = (( (!index && index != 0) || index>=ISRILglobals.ListFilteredSize-1)?(-1):(index));
var next = ISRILglobals.ListIndexN[ index + 1 ];
ISRIL.OpenById( next );
},
RandRead : function() {
//need to do the filtered search here too
if (ISRILglobals.ListFilteredSize > 0) {
var index = Math.floor(Math.random()*ISRILglobals.ListFilteredSize);
var next = ISRILglobals.ListIndexN[ index ];
var r = ISRIL.sBookmarks.getBookmarkURI(next).spec;
if (r != ISRIL.url() || ISRILglobals.ListSize<=1) {
ISRIL.OpenById( next );
} else {
ISRIL.RandRead();
}
}
},
// --- //
GoToFeed : function() {
ISRIL.GoTo('https://readitlaterlist.com/users/'+ISRILsync.feedId());
},
online : function(p) {
p = ((p && p.match(new RegExp('([a-z]+)')))?(p):('unread'));
ISRIL.GoTo('http://readitlaterlist.com/'+p);
},
// --- Queries --- //
InList : function(url, checkParsed) {
//checks for the given url, if it doesn't find it, it parses the url as the server would and tries that
var marks = PlacesUtils.getBookmarksForURI( ISRIL.uri( url ) );
for(var i=0; i<marks.length; i++) {
if ( ISRIL.sBookmarks.getFolderIdForItem( marks[i] ) == ISRILglobals.folderId ) {
return marks[i];
}
}
if (!checkParsed) {
parsed = ISRIL.parseUrl(url);
if (parsed != url) {
return ISRIL.InList(parsed, true);
}
}
return false;
},
GetList : function(s, filter, reuse) {
s = ( (!s) ? (11) : (s) );
if (!reuse || !ISRILglobals.ListResult) {
filter = ( (!filter) ? (0) : (filter) );
// -- Search Bookmarks -- //
var options = ISRIL.sHistory.getNewQueryOptions();
var query = ISRIL.sHistory.getNewQuery();
query.setFolders([ISRILglobals.folderId], 1);
ISRILglobals.ListResult = ISRIL.sHistory.executeQuery(query, options);
}
ISRILglobals.ListResult.sortingMode = s;
var rootNode = ISRILglobals.ListResult.root;
rootNode.containerOpen = true;
// -- Process Results -- //
ISRIL.resetCache();
var l = new Object();
li = 0; kk = '';
for (var i = 0; i < rootNode.childCount; i ++) {
var node = rootNode.getChild(i);
if (PlacesUtils.nodeIsBookmark(node)) {
if (ISRIL.ProcessItem(node, filter)) {
l[li] = node;
li++;
}
}
}
// close a container after using it!
rootNode.containerOpen = false;
// Update unread counter
ISRILxul.UpdateUnreadCounter();
return l;
},
ProcessItem : function(node, filter) {
rFilter = new RegExp(filter, 'i');
ISRILglobals.ListCache[node.itemId] = node.uri;
ISRILglobals.ListSize++;
// -- Filter by title, domain, and tag -- //
if (!filter || filter == ISRILxul.Filter.emptyText || (node.title.match( rFilter ) || node.uri.match( rFilter ) || (node.tags && node.tags.match( new RegExp(filter+'([^,]+)?($|,)', 'i') )))) {
ISRILglobals.ListIndexN[ISRILglobals.ListFilteredSize] = node.itemId;
ISRILglobals.ListIndexI[node.itemId] = ISRILglobals.ListFilteredSize;
ISRILglobals.ResolverIndex[ node.uri ] = {itemId: node.itemId};
ISRILglobals.ListFilteredSize++;
return true;
}
},
resetCache : function() {
ISRILglobals.CacheStale = false;
ISRILglobals.ListIndexN = new Array();
ISRILglobals.ListIndexI = new Array();
ISRILglobals.ListCache = new Array();
ISRILglobals.ResolverIndex = ISRIL.ResolverIndex();
ISRILglobals.ListSize = 0;
ISRILglobals.ListFilteredSize = 0;
},
rePopCache : function(l) {
ISRIL.resetCache();
for(i in l) {
}
},
CacheAdd : function(id, url) {
ISRILglobals.ListCache[ id ] = url;
ISRILglobals.ResolverIndex[ url ] = {itemId: id};
ISRILglobals.CacheStale = true;
},
ListSizeInc : function(i) {
ISRILglobals.ListSize += i;
ISRILxul.UpdateUnreadCounter();
},
ResolverIndex : function() {
var index = {};
var sql = "SELECT id, original_url FROM ril_link_resolver"
var statement = ISRIL.DB.createStatement(sql);
while (statement.executeStep()) {
id = statement.getInt32(0);
url = statement.getUTF8String(1);
index[ url ] = {itemId: id}
}
statement.reset();
return index;
},
GetAllFolders : function(folderId, level) {
var level = ( (!level) ? (0):(level) );
if (level > 2) { return level; } else { level++; }
var result = PlacesUtils.getFolderContents( ( (!folderId) ? (ISRIL.sBookmarks.bookmarksMenuFolder):(folderId) ) );
var rootNode = result.root;
// -- Process Results -- //
var k = 0;
var folderNodes = new Object();
for (var i = 0; i < rootNode.childCount; i ++) {
var node = rootNode.getChild(i);//nodeIsLivemarkContainer
if (PlacesUtils.nodeIsFolder(node) && !PlacesUtils.nodeIsLivemarkContainer(node)) {
folderNodes[k] = {node:node,subs:ISRIL.GetAllFolders(node.itemId, level)};
k++;
}
}
return folderNodes;
},
bookmark : function(bi) { if (bi == 47) { return ISRIL.bookmarkFF() }
ISRIL.GoTo( ISRIL_sites[ bi ][1].replace('<URL>', ISRIL.url()).replace('<TITLE>', ISRIL.title()) );
arr = ISRILprefs.pref('sites').replace( new RegExp('(,)'+bi+'($|,)'), '$2' ).split(',');
arr[0] = bi;
if (arr.length > 6) { arr.pop(); }
ISRILprefs.setPref("sites", ',' + arr.join(',') );
},
bookmarkFF : function(bi) {
ISRILxul.closeAnd();
PlacesUIUtils.showAddBookmarkUI( ISRIL.uri(ISRIL.url()) , ISRIL.title() );
},
bookmarkMore : function() {
var bi = ISRILxul.markAndMore.selectedItem.getAttribute('i');
ISRIL.MarkAsRead(null, null, bi);
ISRIL.bookmark( bi );
},
// -- SQlite Database -- //
Connect : function() {
if (!ISRIL.DB) {
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
file.append("ril.sqlite");
ISRIL.DB = ISRIL.sDB.openDatabase(file);
ISRIL.CreateTables();
return ISRIL.DB;
}
},
CreateTables : function() {
try {
ISRIL.DB.executeSimpleSQL("CREATE TABLE ril_sync_queue (id INTEGER,type TEXT, dateUpdated INTEGER, url TEXT, PRIMARY KEY (id,type))");
ISRIL.DB.executeSimpleSQL("CREATE INDEX type ON ril_sync_queue ( type )");
ISRIL.DB.executeSimpleSQL("CREATE INDEX dateAdded ON ril_sync_queue ( dateAdded )");
} catch(e) { }
try {
ISRIL.DB.executeSimpleSQL("CREATE TABLE ril_link_resolver (id INTEGER PRIMARY KEY NOT NULL , original_url VARCHAR)");
} catch(e) { }
},
// --- Shortcuts --- //
formatKey : function(modifiers, key, keycode) {
modifiers = ((modifiers)?(modifiers.split(' ').join(' + ') + ' + '):(''));
return modifiers + ((key)?(key):(keycode));
},
NewKey : function(key, oncommand) {
ISRILxul.removeNode(ISRILxul.bip(key));
var keySet = ISRILprefs.pref(key).split('||');
var key = ISRILxul.createNode('key', {id:ISRILxul.dPrefix + key,modifiers:keySet[0],oncommand:oncommand} );
key.setAttribute( ((keySet[1].length > 1)?('keycode'):('key')) , keySet[1]);
return key;
},
SetupKeyStrokes : function() {
keySet = ISRILxul.bi('mainKeyset');
if (keySet) {
keySet.appendChild( ISRIL.NewKey('hotkey_toggle', "ISRIL.HotKeyToggle()" ) );
keySet.appendChild( ISRIL.NewKey('hotkey_push', "ISRIL.HotKeyPush()" ) );
keySet.appendChild( ISRIL.NewKey('hotkey_open_list', "ISRIL.HotKeyOpenList()" ) );
keySet.appendChild( ISRIL.NewKey('hotkey_click_mode', "ISRIL.HotKeyClickMode()" ) );
}
},
HotKeyToggle : function() {
( (!ISRIL.InList(ISRIL.url())) ? (ISRIL.Save()):(ISRIL.MarkAsRead(null)) );
ISRIL.checkPage();
},
HotKeyPush : function() {
//act like reading list button was pushed
return ISRIL.Read();
},
HotKeyOpenList : function() {
//toggle reading list
ISRILxul.ToggleReadingList();
},
HotKeyClickMode : function() {
//toggle click save mode
( (!ISRIL.CheckNotify()) ? (ISRIL.ClickSaveMode()):(ISRIL.ClickSaveModeOff()) );
},
keyCodeConvert : function(c, to) {
//return ( (!to) ? (String.fromCharCode(c)):(c.toUpperCase().charCodeAt(0)) );
return c.toUpperCase();
},
hotkeyText : function(p) {
var key;
var keycode;
var keySet = ISRILprefs.pref('hotkey_'+p).split('||');
if (keySet[0].length > 1) {
key = null;
keycode = keySet[1];
} else {
key = keySet[1];
keycode = null;
}
return ISRIL.formatKey( keySet[0], key, keycode );
},
// --- //
ClickSaveMode : function() {
if (!ISRIL.CheckNotify()) { ISRIL.ClickSaveModeOff(); }
content.document.addEventListener("click", ISRIL.ClickSave, false);
ISRIL.NotifyClickMode();
},
ClickSaveModeOff : function() {
ISRIL.RemoveNotify();
content.document.removeEventListener("click", ISRIL.ClickSave, false);
},
ClickSave : function(e) {
var targ;
if (gContextMenu) { a = gContextMenu.target; } else {
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
var a = ISRIL.BubbleToTagName(targ, 'A');
e.preventDefault();
}
if (a && (ISRIL.CheckNotify() || gContextMenu) ) {
if (ISRILprefs.pref('link-checks') != 'no') {
newNode = ISRIL.ClickSavedNode();
if (e) {
X = e.pageX;
Y = e.pageY;
} else {
coords = ISRIL.findPos(a);
X = coords[0];
Y = coords[1];
}
newNode.style.left = (X + 10)+"px";
newNode.style.top = (Y - 15)+"px";
}
var title = ISRIL.strip_tags(a.innerHTML);
if (title.length == 0) {
if (a.firstChild) { //If it doesn't have content then it's probably an image link, so check the image for a title or alt label first
if (a.firstChild.title.length > 0) {
title = a.firstChild.title;
} else if (a.firstChild.alt.length > 0) {
title = a.firstChild.title;
}
}
}
ISRIL.SaveLink(a.href, title);
}
},
BubbleToTagName : function(obj, tagName) {
var maxlvls = 10;
var lvl = 1;
while (obj.tagName != tagName) {
if (obj.parentNode) {
obj = obj.parentNode;
}
if (lvl >= maxlvls) { return false; }
lvl++;
}
return obj;
},
ClickSavedNode : function() {
var newNode = content.document.createElement('div');
var id = 'readitlatersaved'+ISRIL.ClickModeNodesN;
newNode.setAttribute('id', id);
//newNode.className = 'readitlatersaved';
newNode.setAttribute('style', 'width:24px;height:24px;position:absolute;font-size:10px;font-weight:bold;color:#000000;background:url(\'chrome://isreaditlater/skin/markfull24.png\');z-index:100000');
//newNode.innerHTML = 'Saved!';
content.document.body.appendChild(newNode);
if (ISRILprefs.pref('link-checks') == 'hide') {
setTimeout('ISRIL.ClickSavedNodeRemove("'+id+'")', 1500);
}
ISRIL.ClickModeNodesN++;
return newNode;
},
ClickSavedNodeRemove : function(id) {
ISRILxul.removeNode(content.document.getElementById(id));
},
NotifyClickMode : function() {
msg = ISRIL.l('ClickModeNotify');
name = 'ISRILclickmode';
icon = 'chrome://isreaditlater/skin/markfull16.png';
buttons = [{
label: ISRIL.l('TurnOff') + ' ' + '('+ISRIL.hotkeyText('click_mode')+')',
popup: null,
callback: ISRIL.ClickSaveModeOff,
}];
return ISRIL.GetNotify(name, msg, icon, buttons);
},
// --- Notification Box --- //
GetNotify : function(name, msg, icon, buttons) {
var notificationBox = gBrowser.getNotificationBox();
if (!notificationBox.getNotificationWithValue(name)) {
return notificationBox.appendNotification(msg, name,
icon, notificationBox.PRIORITY_WARNING_MEDIUM, buttons);
}
},
CheckNotify : function(name) {
var name = ( (name)?(name):('ISRILclickmode') );
var notificationBox = gBrowser.getNotificationBox();
if (notificationBox.getNotificationWithValue(name)) {
return notificationBox;
}
},
RemoveNotify : function(name) {
var notificationBox = ISRIL.CheckNotify();
if (notificationBox) {
notificationBox.removeCurrentNotification();
}
},
// --- Observers --- //
observe: function(aSubject, topic, data) {
if (topic == "quit-application-requested") {
if (ISRILprefs.prefB('feed') && ISRILsync.QueueExists() > 0) {
var promptIt = ISRILprefs.prefB('shutdown-prompt');
var doIt = ISRILprefs.prefB('shutdown-send');
if (promptIt) {
var check = {value:false};
doIt = ISRILxul.sPrompt.confirmCheck(window, ISRIL.l('ReadItLater'), ISRIL.l('SyncShutdown') , ISRIL.l('DoNotAskAgain'), check );
promptIt = !check.value;
ISRILprefs.setPref('shutdown-prompt', promptIt);
ISRILprefs.setPref('shutdown-send', doIt);
}
if (doIt) {
//stop shutdown
aSubject.QueryInterface(Components.interfaces.nsISupportsPRBool);
aSubject.data = true;
//start syncing, send callback to shutdown when done
ISRIL.shutdownWaiting = true;
ISRILsync.sendUpdates( 'shutdown' );
}
}
}
},
shutdown : function() {
if (ISRIL.shutdownWaiting) {
var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
getService(Components.interfaces.nsIAppStartup);
appStartup.quit( Components.interfaces.nsIAppStartup.eAttemptQuit );
}
},
// --- Version Porting --- //
reMapPrefs : function() {
ISRILprefs.setPrefIfNot("prefsites", ',6,7,47,19,26,44');
ISRILprefs.setPrefIfNot("pref_open", 'same');
ISRILprefs.setPrefIfNot("pref_read", 'rand');
ISRILprefs.setPrefIfNot("pref_mark", 'go');
},
// --- Localization --- //
l : function(l) {
return ISRILxul.bip('strings').getString(l);
},
// --- Service --- //
runBatched: function() {
this._func.apply(this, this._args);
},
// --- Utility --- //
note : function(type) { //gets an annotation name for a type
return ISRIL.appId+"/"+type;
},
sortOnSiteName : function(a, b) {
if (b[1] == '') { return 1; }
var x = a[0].toLowerCase();
var y = b[0].toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
},
whatkeys : function(obj) {
str = '';
for(keys in obj) { str += ' | ' + keys; }
return str;
},
arStr : function(obj) {
str = '';
for(keys in obj) { str += ' | ' + keys + ':' + obj[keys]; }
return str;
},
now : function() {
var d = new Date();
return d.getTime();
},
B2S : function(bool) {
return ((bool) ? ('1'):('0'));
},
rTrim : function(str, mask) {
if (str && str.length > 0) {
return str.substr(0, str.lastIndexOf(mask));
} return '';
},
TrimArray : function(arr) {
newArr = new Array();
p = 0;
for(var i in arr) {
val = arr[i].replace(/^[\s\r]|[\s\r]$/g, '');
if (val.length > 0) {
newArr[p] = val;
p++;
}
}
return arr;
},
d : function(str) { if (ISRIL.debug) { return dump(str+"\n"); } },
strip_tags : function(str){
return str.replace(/<\/?[^>]+>/gi, '');
},
e : function(str) {
return encodeURIComponent(str);
},
findPos : function (obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
},
t : function() {
ISRILglobals.t = ISRIL.now();
ISRILglobals.ts = ISRIL.now();
},
ts : function(s) {
ISRIL.d(s + ' = ' + (ISRIL.now() - ISRILglobals.ts) + ' | ' + (ISRIL.now() - ISRILglobals.t));
ISRILglobals.ts = ISRIL.now();
},
parseUrl : function(url) {
if (url) {
parsed = ISRIL.parseUri(url);
/**********
Updates to this logic need to be updated in the parse url server side function
***********/
parsed.host = parsed.host.toLowerCase().replace('www.', ''); //remove www. and make domain lowercase
parsed.path = parsed.path.replace(new RegExp('/$'), ''); //remove trailing slash
return parsed.protocol + '://' + parsed.host + parsed.path + parsed.query + ((parsed.anchor)?('#'+parsed.anchor):(''));
}
},
/*
parseUri 1.2.1
(c) 2007 Steven Levithan <stevenlevithan.com>
MIT License
*/
parseUri : function (str) {
var o = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
}
var m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
},
/* --- Listeners --- */
listener_linkResolve : function(callback, url, a, offline) {
this.c = a;
this.callback = callback;
this.a = a;
this.url = url;
this.offline = offline;
this.maxDataOns = 3;
this.totalDataOns = 0;
},
}
var ISRIL = new ISRILmaster();
/* --- Listener Prototypes --- */
ISRIL.listener_linkResolve.prototype = {
mData: "",
// nsIStreamListener
onStartRequest: function (aRequest, aContext) {
},
onDataAvailable: function (aRequest, aContext, aStream, aSourceOffset, aLength) {
if (this.totalDataOns < this.maxDataOns) {
var scriptableInputStream =
Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
scriptableInputStream.init(aStream);
this.totalDataOns++;
} else {
this.onStopRequest(aRequest, aContext);
}
},
onStopRequest: function (aRequest, aContext, aStatus) {
if ( ISRIL.channels[this.c] ) {
this.callback( ISRIL.channels[this.c].URI.spec , this.a , this.offline );
ISRIL.channels[this.c] = null;
}
},
// nsIChannelEventSink
onChannelRedirect: function (aOldChannel, aNewChannel, aFlags) {
// if redirecting, store the new channel
ISRIL.channels[this.c] = aNewChannel;
},
// nsIInterfaceRequestor
getInterface: function (aIID) {
try {
return this.QueryInterface(aIID);
} catch (e) {
throw Components.results.NS_NOINTERFACE;
}
},
// nsIProgressEventSink (not implementing will cause annoying exceptions)
onProgress : function (aRequest, aContext, aProgress, aProgressMax) { },
onStatus : function (aRequest, aContext, aStatus, aStatusArg) { },
// nsIHttpEventSink (not implementing will cause annoying exceptions)
onRedirect : function (aOldChannel, aNewChannel) { },
// we are faking an XPCOM interface, so we need to implement QI
QueryInterface : function(aIID) {
if (aIID.equals(Components.interfaces.nsISupports) ||
aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
aIID.equals(Components.interfaces.nsIChannelEventSink) ||
aIID.equals(Components.interfaces.nsIProgressEventSink) ||
aIID.equals(Components.interfaces.nsIHttpEventSink) ||
aIID.equals(Components.interfaces.nsIStreamListener))
return this;
throw Components.results.NS_NOINTERFACE;
}
};
// -- Bookmark Site Data -- //
var ISRIL_sites = new Object();
//UPDATE COUNT HERE FOR RECORD: 48
ISRIL_sites[47] = new Array( 'Firefox Bookmarks' , '' );
ISRIL_sites[0] = new Array( 'BlinkBits' , 'http://blinkbits.com/bookmarklets/save.php?v=1&source_url=<URL>&Title=<TITLE>' );
ISRIL_sites[1] = new Array( 'BlinkList' , 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url=<URL>&Title=<TITLE>' );
ISRIL_sites[2] = new Array( 'Blogmarks' , 'http://blogmarks.net/my/new.php?mini=1&title=<TITLE>&url=<URL>' );
ISRIL_sites[3] = new Array( 'Buddymarks' , 'http://buddymarks.com/add_bookmark.php?bookmark_title=<TITLE>&bookmark_url=<URL>' );
ISRIL_sites[4] = new Array( 'CiteUlike' , 'http://www.citeulike.org/posturl?url=<URL>&title=<TITLE>' );
ISRIL_sites[5] = new Array( 'Connotea' , 'http://www.connotea.org/add?continue=return&uri=<URL>&title=<TITLE>' );
ISRIL_sites[6] = new Array( 'del.icio.us' , 'http://del.icio.us/post?url=<URL>&title=<TITLE>' );
ISRIL_sites[7] = new Array( 'Digg it' , 'http://digg.com/submit?phase=2&url=<URL>&title=<TITLE>' );
ISRIL_sites[37] = new Array( 'Diigo' , 'http://www.diigo.com/post?url=<URL>&title=<TITLE>' );
ISRIL_sites[39] = new Array( 'DZone' , 'http://www.dzone.com/links/add.html?url=<URL>&title=<TITLE>' );
ISRIL_sites[8] = new Array( 'Earthlink' , 'http://myfavorites.earthlink.net/my/add_favorite?v=1&url=<URL>&title=<TITLE>" target="_blank' );
ISRIL_sites[46] = new Array( 'Faves' , 'http://faves.com/Authoring.aspx?u=<URL>&t=<TITLE>' );
ISRIL_sites[9] = new Array( 'FeedMarker' , 'http://www.feedmarker.com/admin.php?do=bookmarklet_mark&url=<URL>&title=<TITLE>;' );
ISRIL_sites[10] = new Array( 'Flog this!' , 'http://www.flogz.com/submit?url=<URL>" title="personal finance and investing news website' );
ISRIL_sites[11] = new Array( 'feedmelinks' , 'http://feedmelinks.com/categorize?from=toolbar&op=submit&name=<TITLE>&url=<URL>' );
ISRIL_sites[12] = new Array( 'Furl' , 'http://www.furl.net/savedialog.jsp?p=1&u=<URL>&t=<TITLE>&r=&v=1&c=' );
ISRIL_sites[13] = new Array( 'Give a Link' , 'http://www.givealink.org/cgi-pub/bookmarklet/bookmarkletLogin.cgi?&uri=<URL>&title=<TITLE>' );
ISRIL_sites[36] = new Array( 'Google' , 'http://www.google.com/bookmarks/mark?op=edit&bkmk=<URL>&title=<TITLE>' );
ISRIL_sites[14] = new Array( 'Gravee' , 'http://www.gravee.com/account/bookmarkpop?u=<URL>&t=<TITLE>' );
ISRIL_sites[15] = new Array( 'igooi' , 'http://www.igooi.com/addnewitem.aspx?self=1&noui=yes&jump=close&url=<URL>&title=<TITLE>' );
ISRIL_sites[16] = new Array( 'Lilisto' , 'http://lister.lilisto.com/?t=<TITLE>&l=<URL>' );
ISRIL_sites[17] = new Array( 'Linkagogo' , 'http://www.linkagogo.com/go/AddNoPopup?title=<TITLE>&url=<URL>' );
ISRIL_sites[18] = new Array( 'Linkroll' , 'http://linkroll.com/insert.php?url=<URL>&title=<TITLE>' );
ISRIL_sites[41] = new Array( 'Looklater' , 'http://api.looklater.com/bookmarks/save?url=<URL>&title=<TITLE>' );
ISRIL_sites[19] = new Array( 'ma.gnolia' , 'http://ma.gnolia.com/bookmarklet/add?url=<URL>&title=<TITLE>' );
ISRIL_sites[20] = new Array( 'Maple.nu' , 'http://www.maple.nu/bookmarks/bookmarklet?bookmark[url]=<URL>&bookmark[description]=<TITLE>' );
ISRIL_sites[45] = new Array( 'Mr. Wong' , 'http://www.mister-wong.de/index.php?action=addurl&bm_url=<URL>&bm_description=<TITLE>' );
ISRIL_sites[21] = new Array( 'My-Tuts' , 'http://user.my-tuts.com/tag-tutorial/?title=<TITLE>&url=<URL>' );
ISRIL_sites[38] = new Array( 'Netscape' , 'http://www.netscape.com/submit/?U=<URL>&T=<TITLE>' );
ISRIL_sites[22] = new Array( 'Netvouz' , 'http://www.netvouz.com/action/submitBookmark?url=<URL>&title=<TITLE>&popup=no' );
ISRIL_sites[23] = new Array( 'Newsvine' , 'http://www.newsvine.com/_wine/save?popoff=0&u=<URL>&h=<TITLE>' );
ISRIL_sites[24] = new Array( 'Onlywire' , 'http://www.onlywire.com/b/?u=<URL>&t=<TITLE>;' );
ISRIL_sites[25] = new Array( 'RawSugar' , 'http://www.rawsugar.com/pages/tagger.faces?turl=<URL>&tttl=<TITLE>' );
ISRIL_sites[42] = new Array( 'RecommendzIt' , 'http://recommendit.dehsoftware.com/bookmarks.php?action=add&address=<URL>&title=<TITLE>&description=' );
ISRIL_sites[26] = new Array( 'reddit' , 'http://reddit.com/submit?url=<URL>&title=<TITLE>' );
ISRIL_sites[27] = new Array( 'Scuttle' , 'http://scuttle.org/bookmarks.php/pass?action=add&address=<URL>&title=<TITLE>' );
ISRIL_sites[43] = new Array( 'Segnalo' , 'http://segnalo.com/post.html.php?url=<URL>&title=<TITLE>&description=' );
ISRIL_sites[28] = new Array( 'Shadows' , 'http://www.shadows.com/features/tcr.htm?url=<URL>&title=<TITLE>' );
ISRIL_sites[29] = new Array( 'Simpy' , 'http://simpy.com/simpy/LinkAdd.do?note=<TITLE>&href=<URL>' );
ISRIL_sites[30] = new Array( 'Spurl' , 'http://www.spurl.net/spurl.php?url=<URL>&title=<TITLE>' );
ISRIL_sites[40] = new Array( 'Squidoo' , 'http://www.squidoo.com/lensmaster/bookmark?<URL>' );
ISRIL_sites[44] = new Array( 'StumbleUpon' , 'http://www.stumbleupon.com/submit?url=<URL>&title=<TITLE>' );
ISRIL_sites[31] = new Array( 'Taggly' , 'http://taggly.com/bookmarks.php/pass?action=add&address=<URL>' );
ISRIL_sites[32] = new Array( 'tagtooga' , 'http://www.tagtooga.com/tapp/db.exe?c=jsEntryForm&b=fx&title=<TITLE>&url=<URL>' );
ISRIL_sites[33] = new Array( 'TalkDigger' , 'http://www.talkdigger.com/index.php?surl=<URL>' );
ISRIL_sites[34] = new Array( 'Wink' , 'http://www.wink.com/_/tag?url=<URL>&doctitle=<TITLE>' );
ISRIL_sites[35] = new Array( 'Yahoo MyWeb' , 'http://myweb2.search.yahoo.com/myresults/bookmarklet?t=<TITLE>&u=<URL>' );